package com.uu.it.tracker.sensordata;

import com.uu.it.tracker.computation.Calculator;
import com.uu.it.tracker.computation.Calculator.StatusBand;
import com.uu.it.tracker.sensordata.SensorData.Gestures;

public class LegSensorData extends SensorData{
	/**
	 * standing if data is in [standingStatusLowLimit, standingStatusUpLimit)
	 * */
	private final static StatusBand standingLegStatusLowBand = new StatusBand(0, 0);

	private final static StatusBand standingLegStatusUpBand = new StatusBand(151, 146);
	/**
	 * walking if data is in [standingStatusUpLimit, walkingStatusUpLimit)
	 * */
	private final static StatusBand walkingLegStatusUpBand = new StatusBand(501, 511);
	/**
	 * running if data is in [standingStatusUpLimit, runningStatusUpLimit)
	 * */
	private final static StatusBand runningLegStatusUpBand = new StatusBand(1501, 1301);
	
	public LegSensorData(int x, int y){
		super(x, y);
	}
	
	/**
	 * if data is in [lowBand, upBand), then return true.
	 * */
	public boolean isInStandingRange(SensorData prevData) {
		int x = Math.abs(prevData.xacc - xacc);
		int y = Math.abs(prevData.yacc - yacc);
		return isInRange(x, y, standingLegStatusLowBand, 
				standingLegStatusUpBand);
	}
	
	/**
	 * if data is in [lowBand, upBand), then return true.
	 * */
	public boolean isInWalkingRange(SensorData prevData) {
		int x = Math.abs(prevData.xacc - xacc);
		int y = Math.abs(prevData.yacc - yacc);
		return isInRange(x, y, standingLegStatusUpBand, 
				walkingLegStatusUpBand);
	}
	
	/**
	 * if data is in [lowBand, upBand), then return true.
	 * */
	public boolean isInRunningRange(SensorData prevData) {
		int x = Math.abs(prevData.xacc - xacc);
		int y = Math.abs(prevData.yacc - yacc);
		return isInRange(x, y, walkingLegStatusUpBand, 
				runningLegStatusUpBand);
	}
	
	/**
	 * Compute the data's proportion in the range
	 * */
	public float computeProportion(Gestures g, SensorData prevData) {
		int x = Math.abs(prevData.xacc - xacc);
		int y = Math.abs(prevData.yacc - yacc);
		switch(g){
		case STAND:
			return Calculator.StatusBand.computeXYProportion(x, y, 
					standingLegStatusLowBand, standingLegStatusUpBand);
		case WALK:
			return Calculator.StatusBand.computeXYProportion(x, y, 
					standingLegStatusUpBand, walkingLegStatusUpBand);
		case RUN:
			return Calculator.StatusBand.computeXYProportion(x, y, 
					walkingLegStatusUpBand, runningLegStatusUpBand);
		default:
			return 0;
		}
	}

	
}
